package com.gt.web.controller.app.dict;

import com.github.pagehelper.PageInfo;
import com.gt.app.domain.PageParam;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.core.domain.entity.SysDictData;
import com.gt.common.utils.PageUtils;
import com.gt.system.mapper.SysDictDataMapper;
import com.gt.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("dict")
@Api(tags = "字典查询接口")
public class DictController extends BaseController {

    @Autowired
    private ISysDictDataService iSysDictDataService;

    @Autowired
    private SysDictDataMapper dictDataMapper;

    @ApiOperation(value = "获取所有字典数据")
    @GetMapping(value = "getDictData")
    public AjaxResult getDictData(PageParam pageParam) {
        startPage();
        List<SysDictData> dictData = iSysDictDataService.getDictData();
        return AjaxResult.success(getDataTable(dictData));
    }

    @ApiOperation(value = "根据字典类型查询字典数据")
    @GetMapping(value = "selectDictDataByType")
    public AjaxResult selectDictDataByType(String dictType) {
        List<SysDictData> dictData = dictDataMapper.selectDictDataByType(dictType);
        return AjaxResult.success(dictData);
    }

}
